import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

public class App {
    public static void main(String[] args) throws JsonProcessingException {
        //1.传建一个json对象
        ObjectMapper objectMapper=new ObjectMapper();
        //2.将对象转换成json字符串
        Student student=new Student();
//        student.setId(1);
//        student.setName("Java");
//        student.setPassword("123");
//        String result=objectMapper.writeValueAsString(student);
//        System.out.println(result);

        //------------2.2jiangjson字符串转换为对象
        String jsonStr="{\"id\":2,\"name\":\"list\",\"password\":\"456\"}";
//        Student lisi=objectMapper.readValue(jsonStr,Student.class);
        HashMap<String,Object> map=objectMapper.readValue(jsonStr,HashMap.class);
        for (Map.Entry<String,Object> item:map.entrySet()) {
            System.out.println(item.getKey()+":"+item.getValue());
        }
    }
}
@Setter
@Getter
class Student{
    private int id;
    private String name;
    private String password;

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
